<template>
    <div class="condition-list">
      <div class="condition-item" v-for="(item, index) in conditionList" :key="index">
        <div class="title-name">
          <span>{{$t('zhongqi.setting.conditionGroup')}}{{(index + 1)}}</span>
        </div>
        <div class="criteria-item-detail" v-for="(ele, ind) in item" :key="ind">
          {{$t('zhongqi.setting.when')}}<span>{{moduleStr(ele.module)}}</span>{{$t('zhongqi.setting.internal')}}
          <span v-if="ele.conditionItem.field && ele.conditionItem.field.displayName">{{ele.conditionItem.field.displayName}}</span>
          <span>{{operatorStr(ele.conditionItem.operator)}}： </span>
          <span>{{valueStr(ele.conditionItem)}}</span>
        </div>
      </div>
    </div>
</template>
<script>
import _ from 'lodash';
import { t } from '@src/locales';


export default {
  name: 'condition-list',
  data() {
    return {

    }
  },
  props: {
    conditionList: {
      type: Array,
      default: () => [],
    },
  },
  methods: {
    moduleStr(val) {
      let obj = {
        'task': `${t('common.base.systemKeyword.task')}`,
        'task_receipt': `${t('common.zhongqi.taskReceipt')}`,
        'task_receipt_amount': `${t('zhongqi.setting.taskReceiptAmount')}`,
      }
      return obj[val]
    },
    operatorStr(val) {
      let operatorObj = {
        'like':  this.$t('component.advancedSearch.conditionMap.like'),
        'eq': this.$t('component.advancedSearch.conditionMap.eq'),
        'uneq': this.$t('component.advancedSearch.conditionMap.uneq'),
        'in': this.$t('component.advancedSearch.conditionMap.in'),
        'ex': this.$t('component.advancedSearch.conditionMap.not_in'),
        'between': this.$t('component.advancedSearch.conditionMap.between'),
        'gt': this.$t('component.advancedSearch.conditionMap.gt'),
        'ge': this.$t('component.advancedSearch.conditionMap.ge'),
        'lt': this.$t('component.advancedSearch.conditionMap.lt'),
        'le': this.$t('component.advancedSearch.conditionMap.le'),
        'not_in': this.$t('component.advancedSearch.conditionMap.not_in'),
        'user': this.$t('component.advancedSearch.conditionMap.eq'),
      }
      return operatorObj[val]
    },
    valueStr(conditionItem) {
      // 人员
      if (conditionItem.formType === 'user') {
        if (conditionItem.value && conditionItem.value.length > 0) {
          return conditionItem.value.map(item => item.name).join(',') || '';
        }
      } else if (conditionItem.formType === 'date') {
        if (conditionItem.value && conditionItem.value.length > 0) {
          return `${conditionItem.value[0]} - ${conditionItem.value[1]}`;
        }
      } else if (conditionItem.formType === 'select') {
        let isArr = _.cloneDeep(conditionItem.value)
        if (Array.isArray(isArr)) {
          return isArr.join(',')
        } 
      } else {
        if (conditionItem.value && Array.isArray(conditionItem.value)) {
          return conditionItem.value.join(',')
        } else {
          return conditionItem.value
        }
      }
    },
  }
}

</script>
<style lang="scss">
  .condition-list {
    margin-top: 10px;
    background: #F2F2F2;
    border-radius: 2px;
    .condition-item {
      margin-bottom: 10px;
      border: 1px solid #E8E8E8;
    }
    .title-name {
      padding: 0 8px;
      height: 28px;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #262626;
      line-height: 28px;
      background: #FAFAFA;
    }

    .criteria-item-detail {
      // height: 40px;
      padding: 0 8px;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #595959;
      line-height: 30px;
      background: #fff;
    }
  }
</style>
